package com.tianxiao.faas.application.web.corner;

import com.google.common.collect.Lists;
import com.tianxiao.faas.api.param.corner.ArticleResult;
import com.tianxiao.faas.api.param.corner.BasePageParam;
import com.tianxiao.faas.biz.service.corner.ArticleService;
import com.tianxiao.faas.common.result.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/app/article/")
public class ArticleController {
    @Resource
    private ArticleService articleService;

    @RequestMapping(value = "/list")
    public Result<List<ArticleResult>> list(@RequestBody BasePageParam param) {
        ArrayList<Integer> types = Lists.newArrayList(1);
        List<ArticleResult> results = articleService.page(param, false, types);
        Integer count = articleService.count(param, types);

        return Result.builder().success(true).data(results).pageSize(param.getPageSize()).pageNo(param.getPage())
                .totalCount(count).totalPage();
    }

    @RequestMapping(value = "/get")
    public Result<ArticleResult> get(Long id) {
        ArticleResult results = articleService.get(id);
        return Result.builder().success(true).data(results);
    }
}
